/**
 * 
 */
package org.jfarrell.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

/**
 * @author Jason Farrell
 * Use this class as a means to call FrmMain with all the address information required
 * to setup the connection
 *
 */
public class VideoReceive extends JFrame implements ActionListener
{
	private Font m_formTitleFont = new Font("Arial", Font.BOLD, 16);
	private Color m_formTitleColor = Color.BLACK;
	
	// Form Members
	private JTextField m_txtMonitorIp = new JTextField( 15 );
	private JTextField m_txtMonitorPort = new JTextField( 5 );
	private JTextField m_txtDestinationIp = new JTextField( 15 );
	private JTextField m_txtDestinationPort = new JTextField( 5 );
	
	public VideoReceive()
	{
		super( "Video Receiver Information Required" );
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		Container pane = this.getContentPane();
		pane.setLayout( new BorderLayout() );
		
		pane.add( this.buildTitle(), BorderLayout.NORTH );
		pane.setForeground(this.m_formTitleColor);
		pane.setFont(this.m_formTitleFont);
		
		pane.add( this.buildInterface(), BorderLayout.CENTER );
		pane.add( this.buildButtonPanel(), BorderLayout.SOUTH );
		
		this.pack();
		this.setVisible( true );
	}
	
	private JPanel buildButtonPanel()
	{
		JPanel p = new JPanel();
		p.setLayout( new FlowLayout( FlowLayout.CENTER ) );
		
		JButton button = new JButton( "Setup Connection" );
		button.addActionListener( this );
		p.add( button );
		
		return p;
	}
	
	public void actionPerformed( ActionEvent ev )
	{
		FrmMain main_program = new FrmMain(
				this.m_txtMonitorIp.getText(),
				this.m_txtMonitorPort.getText(),
				this.m_txtDestinationIp.getText(),
				this.m_txtDestinationPort.getText()
			);
		this.setVisible( false );
		main_program.setVisible(true);
	}
	
	private JPanel buildInterface()
	{
		JPanel p = new JPanel();
		TitledBorder titleBorder = BorderFactory.createTitledBorder("All Fields Required");
		p.setBorder( titleBorder );
		
		p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
		p.add( this.addRow(this.m_txtMonitorIp, new JLabel("IP Address to Monitor")) );
		p.add( this.addRow(this.m_txtMonitorPort, new JLabel("Port to Monitor")) );
		p.add( this.addRow(this.m_txtDestinationIp, new JLabel("IP Address of Main Server")) );
		p.add( this.addRow(this.m_txtDestinationPort, new JLabel("Port of the Main Server")) );
		
		return p;
	}
	
	private JPanel addRow( JTextField text, JLabel label )
	{
		JPanel p = new JPanel();
		p.setLayout(new FlowLayout(FlowLayout.LEFT));
		label.setPreferredSize(new Dimension( 150, 10 ) );
		p.add( label );
		p.add( text );
		
		return p;
	}
	
	private JPanel buildTitle()
	{
		JPanel p = new JPanel();
		p.setLayout( new FlowLayout( FlowLayout.CENTER ) );
		
		Font font = new Font( "Arial", Font.BOLD, 20 );
		JLabel title = new JLabel( "Video Receiver Information" );
		title.setForeground(Color.BLUE);
		p.add( title );
		
		return p;
	}
	
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		new VideoReceive();
	}

}
